<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 Documentation - More/More</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Pseudos">Pseudos</a></h4>
      <div class="menu-item"><a href="#Pseudos:once">once</a></div>
      <h4 class="menu-item"><a href="#Events">Events</a></h4>
      <div class="menu-item"><a href="#Events:Events-definePseudo">Events.definePseudo</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1><a href="#">Events.Pseudos</a></h1>
      <p class="description">Defines the <code>:once</code> pseudo event for classes that have implemented the <a href="../../../docs/core/Class/Class.Extras.html#Events">Events</a> class as well as the <code>definePseudos</code> method for adding your own.</p>
      <h1 id="Pseudos"><a href="#Pseudos">Event Pseudos</a></h1>
      <p class="description">Like <a href="../../../docs/more/Element/Element.Event.Pseudos.html">Element.Event.Pseudos</a> for Elements, you can use pseudos for Class Events.
        An event pseudo looks the same as a CSS pseudo: <code>event:pseudo(value)</code>. <code>event</code> is the eventname you used to use, and <code>pseudo</code> is the name
        of the pseudo.</p>
      <h2 id="Pseudos:once"><a href="#Pseudos:once">Pseudo: once</a></h2>
      <p class="description">The event will only fire once.</p>
      <h3>Example</h3>
      <pre class="javascript"><span class="kw2">var</span> database = <span class="kw2">new</span> <span class="kw2">Class</span><span class="br0">(</span><span class="br0">{</span>

&nbsp;
    implements: Events,
&nbsp;
    connect: <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
        <span class="kw1">this</span>.<span class="me1">fireEvent</span><span class="br0">(</span><span class="st0">'connect'</span><span class="br0">)</span>;
    <span class="br0">}</span>

&nbsp;
<span class="br0">}</span><span class="br0">)</span>;
&nbsp;
<span class="kw2">var</span> db = <span class="kw2">new</span> database<span class="br0">(</span><span class="br0">)</span>;
db.<span class="me1">addEvent</span><span class="br0">(</span><span class="st0">'connect:once'</span>, <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>

    <span class="kw3">alert</span><span class="br0">(</span><span class="st0">'i am connected'</span><span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>;
&nbsp;
db.<span class="me1">connect</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// will alert 'i am connected'</span>

db.<span class="me1">connect</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// nothing will happen</span>
</pre>
      <h1 id="Events"><a href="#Events">Events</a></h1>
      <h2 id="Events:Events-definePseudo" class="description"><a href="#Events:Events-definePseudo">Function: Events.definePseudo</a></h2>
      <p class="description">This function defines a new pseudo.</p>
      <h3>Syntax:</h3>
      <pre class="javascript">Events.<span class="me1">definePseudo</span><span class="br0">(</span><span class="kw3">name</span>, fn<span class="br0">)</span>;
</pre>
      <h3>Arguments:</h3>
      <ol>
        <li>name - (<em>string</em>) The pseudo name, for example <code>once</code> will become <code>click:once</code> </li>
        <li>fn - (<em>function</em>) The function that will get fired when the event is fired. This function should decide what will happen with the event, for example execute the event and remove the event</li>
      </ol>
      <h4>Signature:</h4>
      <pre class="javascript">fn<span class="br0">(</span>split, fn, args<span class="br0">)</span>
</pre>
      <ol>
        <li>split - (<em>object</em>) A parsed object of the string passed in addEvent: <code>event:pseudo(value)</code>
          <ul>
            <li>event - (<em>string</em>) the part before the <code>:</code> </li>
            <li>value - (<em>string</em>) between <code>(</code> and <code>)</code> </li>
            <li>pseudo - (<em>string</em>) between the <code>:</code> and <code>(</code> </li>
            <li>original - (<em>string</em>) the original event name, thus <code>event:pseudo(value)</code> </li>
          </ul>
        </li>
        <li>fn - (<em>function</em>) This is the function that has been passed in the <code>addEvent</code> method. So it is the 'fn' in <code>myClass.addEvent('event:pseudo', fn)</code> </li>
        <li>args - (<em>array</em>) The arguments that are passed into the 'fireEvent' method.</li>
      </ol>
      <h3>Example</h3>
      <p>This is how the :once pseudo is implemented</p>
      <pre class="javascript">Events.<span class="me1">definePseudo</span><span class="br0">(</span><span class="st0">'once'</span>, <span class="kw2">function</span><span class="br0">(</span>split, fn, args<span class="br0">)</span><span class="br0">{</span>

    fn.<span class="me1">apply</span><span class="br0">(</span><span class="kw1">this</span>, args<span class="br0">)</span>
    <span class="kw1">this</span>.<span class="me1">removeEvent</span><span class="br0">(</span>split.<span class="me1">original</span>, fn<span class="br0">)</span>;

<span class="br0">}</span><span class="br0">)</span>;
</pre>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
